/*
 * NotTest.h
 *
 * Created on : 24-05-2014
 *     Author : A.W. Janisse
 *
 * Version 1.0: 24-05-2014, Final release
 */

#include "gtest/gtest.h"
#include "Not.h"
#include "Low.h"
#include "High.h"

/**
 * Deze test toon aan dat er het object aangemaakt en opgeruimd (delete) kan
 * worden.
 *
 * De test case is geslaag als de instantie van and niet NULL is en er geen runtime
 * error komen.
 */
TEST(NOT, ConstructorDestructorTest)
{
    Not *notGate = new Not(0,0,"Not");
    ASSERT_TRUE(notGate != NULL);
    delete notGate;
}

/**
 * Deze test toon aan dat de logische NOT functie het juiste reslutaat geeft.
 */
TEST(NOT, LogicNotWorksOK)
{
    Low *lowGate = new Low(10,10,"Low");
    High *highGate = new High(10, 20, "High");
    Not *notGate = new Not(40,40,"Not");

    EXPECT_EQ(true, notGate->getOutputValue());
    EXPECT_EQ(true, notGate->connectEntryTo(lowGate));
    EXPECT_EQ(true, notGate->getOutputValue());
    EXPECT_EQ(true, notGate->removeEntryTo(lowGate));
    EXPECT_EQ(true, notGate->connectEntryTo(highGate));
    EXPECT_EQ(false, notGate->getOutputValue());

    delete lowGate;
    delete highGate;
    delete notGate;
}

/**
 * Deze test controleert of de NOT gate de juiste drawing instruction levert. De drawing instruction is
 * een string waarin informatie staat over de gate zelf maar ook over de connections. In de opbouw
 * van de string wordt rekening gehouden met de logische toestand van de gate.
 */
TEST(NOT, GetDrawingInstructions)
{
    High *h1 = new High(0,0,"High");
    h1->resetNextNumber();

    Gate * g1 = new Not(10, 20, "Not");
    EXPECT_EQ("gate,1,Not,10,20,1,L,L,H\n", g1->getDrawingInstruction());

    Gate * g2 = new Not(40, 50, "Not");
    EXPECT_EQ("gate,2,Not,40,50,1,L,L,H\n", g2->getDrawingInstruction());

    g1->connectEntryTo(h1);
    EXPECT_EQ("connection,H,8,3,10,23\ngate,1,Not,10,20,1,H,L,L\n", g1->getDrawingInstruction());

    delete h1;
    delete g1;
    delete g2;
}
